
// 45.跳跃游戏II
class Solution {
public:
    int jump(vector<int>& nums) {

        // 使用贪心来进行解决
        int n = nums.size();
        int ret = 0;

        int left = 0, right = 0;
        while (left <= right) {
            if (right >= n - 1)
                return ret;
            int tmp = 0;
            ret++;
            for (int i = left; i <= right; i++)
                tmp = max(tmp, i + nums[i]);
            left = right + 1, right = tmp;
        }
        return 0;
    }
};